package com.mall.shopping.services;

import com.mall.shopping.MyProductService;

import com.mall.shopping.converter.MyProductConverter;
import com.mall.shopping.converter.ProductConverter;
import com.mall.shopping.dal.entitys.Item;
import com.mall.shopping.dal.entitys.ItemDesc;
import com.mall.shopping.dal.persistence.ItemMapper;
import com.mall.shopping.dto.MyProductDtoSSS;
import com.mall.shopping.dto.ProductDetailDto;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


@Service
@Component
public class MyProductServiceImpl implements MyProductService {

    @Autowired
    ItemMapper itemMapper;

    @Autowired
    MyProductConverter myProductConverter;

    @Autowired
    ProductConverter productConverter;

    @Override
    public MyProductDtoSSS qureyProductById(Integer productId) {
        return null;
    }

    @Override
    public ProductDetailDto getProductDetails(Integer id) {
        //给返回的对象进行赋值

        Item item = itemMapper.selectByPrimaryKey(id);
        ItemDesc itemDesc =itemMapper.selectItemDesc(id);
        ProductDetailDto productDetailDto = productConverter.convert2ProductDto(item);

        String[] images = new String[1024];
        String image = item.getImage();
        if (image != null && !"".equals(image)) {
            images = image.split(",");
        }
        System.out.println(image);
        productDetailDto.setProductImageSmall(images);
        String image1 = images[0];
        productDetailDto.setProductImageBig(image1);
        productDetailDto.setProductId(id.longValue());
        productDetailDto.setDetail(itemDesc.getItemDesc());
        return productDetailDto;

    }
}
